package com.gds.wiki.cloud.framework.web.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class CheckUtils {

    /***
     * 真实姓名验证
     *
     * @param trueName
     * @return
     */
    public static boolean checkTrueName(String trueName) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String check = "^[\u4E00-\u9FA5]{2,8}(?:·[\u4E00-\u9FA5]{2,8})*$";
        p = Pattern.compile(check); // 验证真实姓名
        m = p.matcher(trueName);
        b = m.matches();
        return b;
    }

    /**
     * 身份证号码验证
     *
     * @param card
     * @return
     */
    public static boolean checkIdentityCard(String card) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        String check = "^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";
        p = Pattern.compile(check);
        m = p.matcher(card);
        b = m.matches();
        return b;
    }


    /**
     * 校验手机号
     * @param str
     * @return
     * @throws PatternSyntaxException
     */
    public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {
        String regExp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(str);
        return m.matches();
    }
}
